<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/10/13 0013
  Time: 上午 10:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>海量卷库</title>
</head>
<style>
    div{
        float: left;
    }
    a{
        text-decoration: none;
        color: darkmagenta;
    }
    .pages{
        padding-left: 20px;
    }
    input[type="button"]{
        border: 0px solid midnightblue;
        width: 100px;
        height: 30px;
        background-color: dodgerblue;
        color: white;
        /*background-color: lightsteelblue;*/
    }
    .examdata{
        border-bottom: 1px solid;
    }
    .hh{
        line-height: 25px;
    }
</style>
<script type="text/javascript" src="/js/jquery-1.8.3.js"></script>

<body>
<div id="show" style="height: 100%;width: 100%; background-color: #E0FFFF">
    <table id="examTb" border="0px solid black" style="margin: 1% auto;width: 85%;line-height: 50px;" cellspacing="0" cellpadding="0">
        <tr>
            <td colspan="6" style="text-align: center;font-size: 50px;font-family: 宋体">
                海量卷库<hr/>
            </td>
        </tr>
        <tr style="line-height: 100px">
            <td colspan="6">
                <input type="text" name="see" id="see" placeholder="请输入考试科目进行搜索" style="width: 40%;height: 35px;margin-left: 25%" ><input type="button" name="seek" style="height: 35px;" id="seek"  value="搜索">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="/teacher/addExamServlet"><strong>+添加试卷</strong></a>
            </td>
        </tr>
        <tr>
            <th>试卷名</th>
            <th>考试时间段</th>
            <th>考试年级</th>
            <th>出题老师</th>
            <th>考试时间</th>
            <th>操作</th>
        </tr>

    </table>
    <div style="margin:1% 40%">
        <a href="javascript:void(0)" id="first" class="pages"><strong>首页</strong></a>
        <a href="javascript:void(0)" id="prev" class="pages"><strong>上一页</strong></a>
        <a href="javascript:void(0)" id="next" class="pages"><strong>下一页</strong></a>
        <a href="javascript:void(0)" id="last" class="pages"><strong>尾页</strong></a><br/>
    </div>
</div>

<div id="shows" style="height: 100%;width: 100%;background-color: #E0FFFF;overflow: auto">
    <table id="up" style="width: 80%;"></table>
    <table id="name1" style="margin: auto;width: 80%;background-color: paleturquoise"></table>
    <table id="xz" style="margin: auto;width: 80%;background-color: paleturquoise">
        <tr><td><h3>选择题</h3></td></tr>
    </table>
    <table id="pd" style="margin: auto;width: 80%;background-color: paleturquoise">
        <tr><td><h3><br/>判断题</h3></td></tr>
    </table>
</div>
<script>
    var currPage;
    var tPages;

    //删除确认提示函数
    function delboard() {
        var answer = confirm("确认删除？");

        if (answer) {
            return true;
        } else {
            return false;
        }

    }

    $(function () {

        /**
         * 姚家乐
         *说明：对试卷的大致浏览和对具体的试卷进行搜索
         */
        var getExamList = function (curr,eid) {

            $.ajax({
                type:"POST",
                url:"/teacher/ExamServlet",
                dataType:"JSON",
                data:{
                    pageSize:10,
                    pageNum:curr||1,
                    see:$("#see").val(),
                    eid:eid||0
                },
                success: function (data) {
                    $("#examTb").find("tr[class='examdata']").remove();
                    $.each(data.examList,function (index,obj) {
                        var $examtr="<tr class='examdata'>" +
                            "<td style='text-align: center'>"+obj.eName+"</td>" +
                            "<td style='text-align: center'>"+obj.eStart+"至"+obj.eEnd+"</td>" +
                            "<td style='text-align: center'>"+obj.grade.gId+"</td>" +
                            "<td style='text-align: center'>"+obj.teacher.teacherName+"</td>" +
                            "<td style='text-align: center'>"+obj.eTime+"</td>" +
                            "<td style='text-align: center'>" +
                            "<input type='button' class='showExam' ename='"+obj.eName+"' estring='"+obj.eString+"' style='width: 80px;' Eid='"+obj.eId+"' value='查看试卷'>&nbsp;" +
                            "<input type='button' class='delExam'style='width: 80px;' code='"+obj.eId+"' value='删除'>" +
                            "</td>" +
                            "</tr>";
                        $("#examTb").append($examtr);
                    });

                    /*删除指定ID的试卷*/
                    $("#examTb").find("input[class='delExam']").click(function () {
                        if (delboard()){
                            eid=$(this).attr("code");
                        } else {
                            eid=0;
                        }
                        getExamList(currPage,eid);
                    });

                    currPage=data.pageNum;
                    tPages=data.total;

                    /*查看试卷详细信息*/
                    $("#examTb") .find("input[class='showExam']").click(function () {
                        ename=$(this).attr("ename");
                        estring=$(this).attr("estring");
                        Eid=$(this).attr("Eid");
                        getShowExam(ename,estring,Eid);
                    });
                }
            });

        }

        /*分页*/
        $(".pages").click(function () {
            var flag=$(this).attr("id");
            if (flag=="first"){
                getExamList(1,0);
            } else if (flag=="prev"){
                currPage--;
                getExamList(currPage,0);
            } else if (flag=="next"){
                currPage++;
                if (currPage>tPages){
                    currPage--;
                }
                getExamList(currPage,0);
            } else if (flag=="last"){
                getExamList(tPages,0);
            }
        });
        /*调用简单查看试卷函数*/
        getExamList();
        /*模糊查询试卷*/
        $("#seek").click(function () {
            getExamList();
        });


        /**
         * 姚家乐
         * 说明：对试卷进行详细的查看，并且可以进行修改
         */
        $("#shows").css("display","none");
        var getShowExam = function (ename,estring,Eid) {
            $("#show").css("display","none");
            $("#shows").css("display","block");
            $.ajax({
                type:"POST",
                url:"/teacher/ShowExamServlet",
                dataType:"JSON",
                data:{
                    estring:estring
                },
                success: function (data) {
                    $("#up").find("tr[class='upExam']").remove();
                    $("#name1").find("tr[class='nname']").remove();
                    $("#xz").find("tr[class='xzs']").remove();
                    $("#pd").find("tr[class='pds']").remove();

                    /*在table中添加入试卷试题*/
                    $.each(data.xzdList,function (index,obj) {
                        var $xztr= "<tr class='xzs'>" +
                            "<td>" +
                            "<table>" +
                            "<tr class='hh'>" +
                            "<td>" +(index+1)+"、"+obj.tN+ "</td>" +
                            "<td>" +"&nbsp;&nbsp;"+obj.ndAn+ "</td>" +
                            "</tr>" +
                            "<tr class='hh'>" + "<td>" +obj.aN+ "</td>" + "</tr>" +
                            "<tr class='hh'>" + "<td>" +obj.bN+ "</td>" + "</tr>" +
                            "<tr class='hh'>" + "<td>" +obj.cN+ "</td>" + "</tr>" +
                            "<tr class='hh'>" + "<td>" +obj.dN+ "<br/></td>" + "</tr>" +
                            "</table>" +
                            "<hr/></td>" +
                            "</tr>" ;
                        $("#xz").append($xztr);
                    });
                    $.each(data.pddList,function (index,o) {
                        var $pdtr="<tr class='pds'>" +
                            "<td>" +
                            "<table>" +
                            "<tr class='hh'>" +
                            "<td>" +(index+1)+"、"+o.tM+ "</td>" +
                            "<td>" +"&nbsp;&nbsp;" +o.mdAn+ "</td>" +
                            "</tr>" +
                            "</table>" +
                            "<hr/></td>" +
                            "</tr>" ;
                        $("#pd").append($pdtr);
                    });

                    /*在对应的table中添加  修改试卷  和  点击隐藏  的功能*/
                    var $uptr="<tr class='upExam'>" + "<td style='text-align: left'>" +
                        "<input type='button' id='ff' style='text-align: center' value='返回'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+
                        "<a href='/teacher/SelectTkServlet?eid="+Eid+"'><input type='button' style='background-color: darkseagreen;color: white' value='修改试卷'></a>" +
                        "</td>" + "</tr>";
                    $("#up").append($uptr);

                    $("#ff").click(function () {
                        $("#shows").css("display","none");
                        $("#show").css("display","block");
                    })


                    /*在对应的table中添加试卷名*/
                    var $name1tr="<tr class='nname'>" + "<td style='text-align: center;line-height: 70px'><h2>" +ename+ "</h2></td>" + "</tr>";
                    $("#name1").append($name1tr);
                }
            });
        }
    })

</script>
</body>
</html>
